'use strict'

process.chdir(__dirname)

const titbit = require('titbit')

const app = new titbit()

//跨域中间件 ===================================================
app.use(async (c, next) => {
  c.setHeader('access-control-allow-origin', '*'); //设置允许访问的域 所有
  c.setHeader('access-control-allow-methods',  //设置允许访问的方法
    ['GET', 'POST', 'PUT', 'DELETE', 'OPTIONS']); 

  c.setHeader('access-control-allow-headers', 'content-type');

  await next();
})
//=================================================================

app.options('/*', async c => {})

app.post('/d', async c => {
  c.send(c.body)
})

app.delete('/d', async c => {
  c.send('delete ok')
})

app.get('/', async c => {
  //c.setHeader('content-type', 'text/html')
  await c.helper.pipe('./index.html', c.reply)
})

app.run(2021)
